home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
(A)P
/
(A)P1.ADF
/
Polygon
/
iffwriter
/
iffwriter2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-05-25
|
4KB
|
139 lines
/*****************************************************************************
* Copyright (C) 1986, =Robert J. Mical=
* Placed in the Public Domain
****************************************************************************/
#include "iffwriter.h"
extern struct RastPort *rp;
extern struct ViewPort *vp;
extern struct Window *w;
extern struct Screen *screen;
extern struct NewScreen ns;
LONG PictModes[3] =
{
CAMG,
4,
NULL,
};
LONG PictBody[2] =
{
BODY,
40000,
};
struct PaintingHeader PaintingHeader =
{
FORM, /* IFFID */
(40156), /* file length */
ILBM,
BMHD,
sizeof(struct BitMapHeader),
{ /* start of the BitMapHeader structure */
320, 200,
0, 0,
5,
0,
0,
0,
0,
10, 11,
320, 200, /* end of BitMapHead */
},
CMAP,
96, /* this value is followed by 32 color registers */
};
char filename[32]="temp.pic";
BOOL SavePicture()
{
SHORT i, j, offset;
ULONG length, actual_length;
UBYTE *p, component, rgbbyte;
USHORT rgb;
BOOL written;
int file,n;
written = FALSE;
/* Open the data file */
file = open(filename,O_WRONLY | O_TRUNC | O_CREAT);
if (file == -1)
goto EXIT_ERROR;
/***********************************************************************
* to write the buffer to the disk, we need to write:
* "FORM"
* file length
* "ILBM"
* "BMHD"
* BMHD length
* BitMapHeader structure
* "CMAP"
* CMAP length
* colors
* pad byte if needed
* "BODY"
* BODY length
* body data
**********************************************************************/
/* First, write out the header */
length = sizeof(struct PaintingHeader);
actual_length = write(file, &PaintingHeader, length);
if (actual_length != length)
goto WRITE_ERROR;
/* also, enough bytes for each color register */
for (i = 0; i < (1 << ns.Depth); i++)
{
for (component = 0; component < 3; component++)
{
rgb = (GetRGB4(vp->ColorMap, i));
rgbbyte = (rgb >> (4 * (2 - component)));
rgbbyte <<= 4;
actual_length = write(file, &rgbbyte, 1);
if (actual_length != 1)
goto WRITE_ERROR;
}
}
actual_length = write(file, &PictBody[0], 8);
if (actual_length != 8)
goto WRITE_ERROR;
/* Finally, the data (uncompressed for now). */
/* First, get the bytelength per line */
length = (((ns.Width + 15) >> 4) << 1);
/* For every line ... */
for (j = 0; j < ns.Height; j++)
{
offset = length * j;
/* For every bit plane ... */
for (i = 0; i < ns.Depth; i++)
{
/* p is set to the start of the line in this bit plane */
p = (screen->BitMap.Planes[i]) + offset;
actual_length = write(file, p, length);
if (actual_length != length) goto WRITE_ERROR;
}
}
PictModes[2] = vp->Modes;
actual_length = write(file, &PictModes[0], 12);
if (actual_length != 12)
goto WRITE_ERROR;
written = TRUE;
WRITE_ERROR:
close(file);
EXIT_ERROR:
for (n=1;n<=500000;n++)
;
return(written);
}